package com.hy;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * <p>
 * User:Mr.Du
 * Date:2024/2/28
 * Time:9:39
 */
public class MinIncrements {

    public int minIncrements(int n, int[] cost) {
        int res = 0;
        int l = cost.length;
        for(int i = l - 2;i > 0;i-=2){
            res += Math.abs(cost[i] - cost[i+1]);
            cost[i / 2] += Math.max(cost[i], cost[i+1]);
        }
        return res;
    }

    public static void main(String[] args) {
        int n = 15;
        int[] costs = new int[]{764,1460,2664,764,2725,4556,5305,8829,5064,5929,7660,6321,4830,7055,3761};
        MinIncrements minIncrements = new MinIncrements();

        int res = minIncrements.minIncrements(n, costs);
        System.out.println(res);
    }
}
